package day06;

import java.util.Arrays;
import java.util.Random;

import static day06.PrintArr.printArr;
import static day06.RandomArr.randomArr;

public class MethodDemo {

    public static void say() {
        System.out.println("hello");
    }

//    public static void randomArr(int[] arr){
//        Random r = new Random();
//        for (int i = 0; i < arr.length; i++){
//            arr[i] = r.nextInt(100);
//        }
//    }

//    public static void printArr(int[] arr) {
//        System.out.print("[");
//        for (int i = 0; i < arr.length; i++) {
//            if (i == arr.length - 1) {
//                System.out.print(arr[i]);
//            } else {
//                System.out.print(arr[i] + ",");
//            }
//        }
//        System.out.print("]");
//        System.out.println();
//    }

    public static String fun() {
        String str = "无参有返回";
        return str;
    }

    //无参有返回
    public static int[] generateArray() {
        int[] arr = new int[10];
        Random r = new Random();
        for (int i = 0; i < 10; i++) {
            arr[i] = r.nextInt(100);
        }
        return arr;
    }

    public static int[] generateArray1(int l, int max) {
        int[] arr = new int[l];
        Random r = new Random();
        for (int i = 0; i < l; i++) {
            arr[i] = r.nextInt(max + 1);
        }
        return arr;
    }

    public static void sayHello(String name, int age) {
        if (age > 66) {
            return;//结束方法
        }
        System.out.println(name + "今年" + age + "岁了");

    }


    public static void main(String[] args) {
        say();
        int[] a = new int[]{1, 2, 3, 5, 7, 4};
        printArr(a);

        int[] b = new int[10];
        randomArr(b);
        printArr(b);

        //String str1 = fun();
        System.out.println(fun());

        int[] c = generateArray();
        System.out.println(Arrays.toString(c));

        Arrays.sort(generateArray());
        System.out.println(Arrays.toString(generateArray()));

        int[] d = generateArray1(20, 50);
        System.out.println(Arrays.toString(d));

        sayHello("zpy", 23);
        sayHello("zpy", 67);


    }

}
